package com.whut.controller;

import com.alibaba.fastjson.JSONArray;
import com.whut.service.AndroidService;
import com.whut.service.GeoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/geo")
public class GeoController {
    @Resource
    private GeoService geoService;
    @Resource
    private AndroidService androidService;

    /*
     * @Author fuzhenjie
     * @Description 从CTP表中挑选出所有合同所有项目（有经纬度）的项目列表
     * @Date 10:27 19.6.23
     * @Param []
     * @return java.lang.Object
     **/
    @ResponseBody
    @PostMapping("/getAllPoint")
    public Object getAllPoint(int contractId) {
        return geoService.getAllPoint(contractId);
    }

    /**
     * 根据这个搜索名称得到这个项目合同信息
     * @param value 搜索的值
     * @return 返回的是一个数组列表
     */
    @ResponseBody
    @PostMapping("/getProjectNamesByValue")
    public Object getProjectNamesByValue(String value,int contractId) {
        return geoService.getProjectNamesByValue(value,contractId);
    }

    /*
     * @Author fuzhenjie
     * @Description 根据给定的合同id找到合同底下的所有工程，找到其地理信息
     * @Date 10:55 19.6.23
     * @Param [contractId]
     * @return java.lang.Object
     **/
    @ResponseBody
    @PostMapping("/getContractProjects")
    public Object getContractProjects(int contractId) {
        return geoService.getProjectsByContractId(contractId);
    }

    /**
     * @author fuzhenjie
     * 得到所有合同列表（未完成的）即委托方列表
     * @date 11:04 19.6.23
     * @return java.lang.Object
     */
    @ResponseBody
    @PostMapping("/getContractList")
    public Object getContractList(){
        return geoService.getContractList();
    }

    /*
     * @Author fuzhenjie
     * @Description 根据合同Id找到合同Id下的特征值统计
     * @Date 15:25 19.6.23
     * @Param [contractId]
     * @return java.lang.Object
     **/
    @ResponseBody
    @PostMapping("/getStatisticsByContractId")
    public Object getStatisticsByContractId(int contractId){
        return geoService.getStatByContractId(contractId);
    }



    /*
     * @Author fuzhenjie
     * @Description 先检验是不是要选择的这个项目的组长，再看这个项目CCT中的projectId的project是不是存过地理位置的信息
     * @Date 20:11 19.7.2
     * @Param [contractId]
     * @return java.lang.Object
     **/
    @ResponseBody
    @PostMapping("/checkIsNeedGeo")
    public String checkIsNeedGeo(int checkId,int userId){
//        return androidService.getIsHead(userId,groupId)
        Boolean isNeed = geoService.getIsNeedGeo(checkId);
        Boolean isGroupId = geoService.getIsHeader(checkId,userId);
        if(isNeed&&isGroupId){
            return "Y";
        }else{
            return "N";
        }
    }

    /*
     * @Author fuzhenjie
     * @Description 根据工程id和经纬度将信息存储在 ctp表
     * @Date 18:58 19.7.3
     * @Param [projectId, longitude, latitude]
     * @return java.lang.String
     **/
    @ResponseBody
    @PostMapping("/saveGeo")
    public String checkIsNeedGeo(int projectId,float longitude,float latitude){
        return geoService.updateGeoByProjectId(projectId,longitude,latitude);
    }
    @ResponseBody
    @PostMapping("/getGeoByProjectId")
    public String getGeoByProjectId(int projectId){
        return geoService.getGeoByProjectId(projectId);
    }


    /*
     * @Author fuzhenjie
     * @Description 给出一个工程的projectId 与搜索开始时间 与搜索结束时间；返回工程详细信息的图表信息来源
     * @Date 20:19 19.7.4
     * @Param [projectId]
     * @return java.lang.Object
     **/
    @ResponseBody
    @PostMapping("/getSingleProjectInfo")
    public Object getSingleProjectInfo(int projectId,int type){
        return geoService.getProjectDetail(projectId,type);
    }


    /**
    * 得到最近三次检查的对比情况（更新）
    *@author fuzhenjie
    *@date 20.1.1 18:01(GMT)
    *@param projectId
    *@param type
    *@return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/getRecentlyTop3CheckCompareDetail")
    public Object getRecentlyTop3CheckCompareDetail(int projectId,int type){
        return geoService.getRecentlyTop3CheckCompareDetail(projectId,type);
    }

    /**
    * 通过合同Id搜索所有合同中的周期
    *@author fuzhenjie
    *@date 20.1.1 19:26(GMT)
    *@param contractId
    *@return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/getCTAByContractId")
    public Object getCTAByContractId(int contractId){
        return geoService.getCTAByContractId(contractId);
    }

    /**
    * 比较周期中的五种隐患的信息
    *@author fuzhenjie
    *@date 20.1.1 19:49(GMT)
    *@param ctaList string
    *@return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/getCTACompareInfo")
    public Object getCTACompareInfo(String ctaList,int type){
        List<Integer> list = JSONArray.parseArray(ctaList,Integer.class);
        return geoService.getCTACompareInfo(list, type);
    }

    @ResponseBody
    @PostMapping("/getSingleProjectRangedTime")
    public Object getSingleProjectRangedTime(int projectId,String st,String et){
        return geoService.getRangedTime(projectId,st,et);
    }
    @ResponseBody
    @PostMapping("/getAllUncompletedPosition")
    public Object getAllPosition() {
        return geoService.getalluncompletedposition();
    }

    @ResponseBody
    @PostMapping("/getAllCompletedPosition")
    public Object getAllCompletedPosition() {
        return geoService.getallcompletedposition();
    }

    @ResponseBody
    @PostMapping("/getPositionByContract")
    public Object getPositionByContract(int contractId) {
        return geoService.getpositionbycontract(contractId);
    }

    @ResponseBody
    @PostMapping("/getPositionById")
    public  Object getPositionById(int projectId) {return geoService.getpositionbyid(projectId);}

    /**
     * 哎呀这里没有合同（委托方）的名字就很烦，所以只能单独取
     *@author fuzhenjie
     *@date 19.9.21 8:01(GMT)
     *@param contractId
     *@return java.lang.Object
     */
    @ResponseBody
    @PostMapping("/getContractInfoById")
    public Object getContractInfoById(int contractId){
        return geoService.getContractInfoById(contractId);
    }

    /**
    * 获取所有包含未完成检查的project信息
    * @author fanyu
    * @date 2020/1/8 19:43
    * @param
    * @return java.lang.Object
    */
    @ResponseBody
    @PostMapping("/getAllUnFinishedProjectInfo")
    public Object getAllUnFinishedProjectId(){return geoService.getAllUnFinishedProjectId();}

    /*根据contractId存入委托方地理坐标contractGeo
    * wxd
    * */
    @ResponseBody
    @PostMapping("/saveContractGeoById")
    public String saveContractGeoById(int contractId,String longitude,String latitude){
        return  geoService.updateContractGeoByContractId(contractId,longitude,latitude);
    }
}
